#!/bin/bash
echo "start formatting new disk"
set -e
set -x

if [ -f /etc/disk_added_date ]
then
   echo "disk already added so exiting."
   exit 0
fi

echo "If fdisk fails with error message as 'Unable to open /dev/sdb', delete ~/.vagrant.d/boxes/centos-6.4-x86_64-smx/0/virtualbox/disk.vdi, then do 'vagrant halt xxxx', 'vagrant up xxxx' and 'vagrant provision xxxx'  again!!!!"

sudo fdisk -u /dev/sdb <<EOF
n
p
1


t
8e
w
EOF

pvcreate -ff -y /dev/sdb1
#vgextend VolGroup /dev/sdb1
#lvextend -l +100%FREE /dev/VolGroup/lv_root
#resize2fs /dev/VolGroup/lv_root
mkfs -t ext4 /dev/sdb1
mkdir -p /mnt/pcslog
if ! (grep -q /dev/sdb1 /etc/fstab); then
 echo "/dev/sdb1	/mnt/pcslog	ext4    defaults        0 0" >> /etc/fstab
fi
mount -a

date > /etc/disk_added_date
